package com.itboye.textileexpres.widget;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.itboye.textileexpres.R;

public class SexPopupWindow extends PopupWindow {
	private TextView men, women, cancel_tv;
	private View cameraMenuView;

	@SuppressWarnings("deprecation")
	public SexPopupWindow(Activity context, OnClickListener itemOnclick) {
		super(context);
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		cameraMenuView = layoutInflater.inflate(R.layout.sex_dialog, null);
		men = (TextView) cameraMenuView.findViewById(R.id.men);
		women = (TextView) cameraMenuView.findViewById(R.id.women);
		cancel_tv = (TextView) cameraMenuView
				.findViewById(R.id.camera_cancel_tv);

		cancel_tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				dismiss();
			}
		});
		men.setOnClickListener(itemOnclick);
		women.setOnClickListener(itemOnclick);
		this.setContentView(cameraMenuView);
		this.setWidth(LayoutParams.FILL_PARENT);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		// this.setAnimationStyle(R.style.AnimBottom);
		ColorDrawable dw = new ColorDrawable(0xb000000);
		this.setBackgroundDrawable(dw);
		cameraMenuView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				int height = cameraMenuView.findViewById(R.id.camera_layout)
						.getTop();
				int y = (int) event.getY();
				if (event.getAction() == MotionEvent.ACTION_UP) {
					if (y < height) {
						dismiss();
					}
				}

				return true;
			}
		});
	}
}
